<?php

/**
 * Created by PhpStorm.
 * User: yinnannan
 * Date: 16/3/1
 * Time: 下午9:31
 */
class userAddress
{
    public function insert($parm){
        DB::update("sysuseraddress")->set(array('isDefault'=>'未默认'))->where('userId','=',$parm['userId'])->execute();

        DB::insert("sysuseraddress",array('provinceId','cityId','address','username','phone','userId','isDefault'))
            ->values(array($parm['provinceId'],$parm['cityId'],$parm['address'],$parm['username'],$parm['phone'],$parm['userId'],$parm['isDefault']))
            ->execute();
    }
    public function getByUserId($parm){
        $result = DB::select('*,(select Name from syschina where syschina.Id=sysuseraddress.provinceId ) as provinceName ,(select Name from syschina where syschina.Id=sysuseraddress.cityid) as cityName')->from('sysuseraddress')->where('userId','=',$parm['userId'])->execute()->as_array();
        return $result;
    }
    public function deleteById($parm){
        DB::delete('sysuseraddress')->where('id','=',$parm['id'])->execute();
    }
}